<template>
  <div>
		<el-space style="margin-bottom: 10px;">
				<el-input v-model="params.code" placeholder="请输入检查项目编码"></el-input>
				<el-input v-model="params.name" placeholder="请输入检查项目名称"></el-input>
				<el-button type="primary" plain @click="search">搜索</el-button>
				<el-button type="warning" plain @click="clear">清空</el-button>
		</el-space>
		<el-table :data="tableData" border @row-dblclick="selected">
			<el-table-column label="编码" prop="code"></el-table-column>
			<el-table-column label="名称" prop="name"></el-table-column>
			<el-table-column label="检查部位" prop="examinationPosition"></el-table-column>
			<el-table-column label="单价" prop="price"></el-table-column>
			<el-table-column label="单位" prop="unit"></el-table-column>
		</el-table>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { get } from '@/axios'
import { ElMessage } from 'element-plus'
import { copy } from 'copy-anything'
const props = defineProps(['items'])
console.dir(props.items)
const tableData = ref([])
const datas = ref([])
const params = reactive({
	code: '',
	name: ''
})
getTableData()
function getTableData () {
	get('/medicalExaminationItem/list', {}, content => {
		datas.value = content
	})
}
function search () {
	if (params.code.trim() === '' && params.name.trim() === '') {
		ElMessage.error('请输入筛选条件')
	} else {
		tableData.value = []
		datas.value.forEach(item => {
			if ((params.code.trim() !== '' && item.code.indexOf(params.code.trim()) !== -1) || (params.name.trim() !== '' && item.name.indexOf(params.name.trim()) !== -1)) {
				tableData.value.push(item)
			}
		})
	}
}
function clear () {
	params.code = ''
	params.name = ''
	tableData.value = []
}
function selected (row) {
	for (const i in props.items) {
		const item = props.items[i]
		if (item.id === row.id) {
			return
		}
	}
	props.items.push(copy(row))
}

</script>

<style scoped lang="scss">
</style>